package com.bckj.freshnow.user.controller;

import com.bckj.freshnow.user.model.UserRequest;
import com.bckj.freshnow.user.model.UserResponse;
import com.bckj.freshnow.user.service.UserService;

import org.springframework.web.bind.annotation.*;

import com.bckj.fastboot.core.page.annotation.PageQuery;
import com.github.pagehelper.PageInfo;

import lombok.RequiredArgsConstructor;
import java.util.List;


/**
 * 用户表(User)表控制层
 *
 * @author makejava
 * @since 2025-04-21 09:36:57
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("")
public class UserController {
    /**
     * 服务
     */
	private final UserService userService;
	
    /**
	 * 列表
	 *
	 * @param request req
	 * @return list
	 */
	@PageQuery
	@GetMapping("page")
	public PageInfo<UserResponse> page(UserRequest request) {
		List<UserResponse> data = userService.findAll(request);
		return new PageInfo<>(data);
	}
	
    /**
	 * 列表
	 *
	 * @param request req
	 * @return list
	 */
	@GetMapping("list")
	public List<UserResponse> list(UserRequest request) {
		return userService.findAll(request);
	}

	/**
	 * 增加
	 *
	 * @param request req
	 * @return boolean
	 */
	@PostMapping
	public boolean save(@RequestBody UserRequest request) {
		return userService.saveUser(request);
	}

	/**
	 * 修改
	 *
	 * @param request req
	 * @return boolean
	 */
	@PutMapping
	public boolean update(@RequestBody UserRequest request) {
		return userService.updateUser(request);
	}

	/**
	 * 移除
	 *
	 * @param id id
	 * @return boolean
	 */
	@DeleteMapping("{id}")
	public boolean remove(@PathVariable Long id) {
		return userService.remove(id);
	}

	/**
	 * 详情
	 *
	 * @param id id
	 * @return vo
	 */
	@GetMapping("{id}")
	public UserResponse details(@PathVariable Long id) {
		return userService.details(id);
	}
}

